#include "../include/warning.h"

void warning_off()
{
    int fd_led = open("/dev/Led", O_RDWR);            
	if(fd_led < 0)
	{
		perror("led open failed");
		return;
	}

    int fd_beep = open("/dev/beep", O_RDWR);           
	if(fd_beep < 0)
    {
		perror("open beep failed");
		return;
	}

    //第二个参数给1， 蜂鸣器静止
    ioctl(fd_beep, OFF, 1);   

    ioctl(fd_led, LED1, OFF);
    ioctl(fd_led, LED2, OFF);
    ioctl(fd_led, LED3, OFF);
    ioctl(fd_led, LED4, OFF);

    close(fd_led);
    close(fd_beep);
}

void* warning_on(void *arg)
{
    int fd_led = open("/dev/Led", O_RDWR);            
	if(fd_led < 0)
	{
		perror("led open failed");
		return NULL;
	}

    int fd_beep = open("/dev/beep", O_RDWR);           
	if(fd_beep < 0)
    {
		perror("open beep failed");
		return NULL;
	}

    while(1)
    {
        //灯亮蜂鸣器响
        ioctl(fd_led, LED1, ON);
        ioctl(fd_led, LED2, ON);
        ioctl(fd_led, LED3, ON);
        ioctl(fd_led, LED4, ON);
        ioctl(fd_beep, ON, 1);
        usleep(500);

        //灯灭蜂鸣器停
        ioctl(fd_led, LED1, OFF);
        ioctl(fd_led, LED2, OFF);
        ioctl(fd_led, LED3, OFF);
        ioctl(fd_led, LED4, OFF);
        ioctl(fd_beep, OFF, 1);
        usleep(500);
    }

    close(fd_beep);
    close(fd_led);
}